/*
 * @Author: tpy、yjw、hjj
 * @Date: 2020-04-02 18:05:53
 * @LastEditTime: 2020-06-23 15:49:46
 * @LastEditors: 最后修改者
 * @Description: 地图操作相关基础功能
 */


const { message } = require('antd');
const maxH = 500;
const Cesium = window.Cesium;
const keystr = ["name", "show", "description", "position", "orientation",
    "viewFrom", "parent", "billboard", "box", "corridor", "cylinder",
    "ellipse", "ellipsoid", "label", "model", "path", "point", "polygon",
    "polyline", "polylineVolume", "rectangle", "wall",
    "STNM", "feaproperties", "EditMarker", "layername"];

/**
 * @description 地图操作基础功能公共类
 * @author tpy、yjw、hjj
 * @annotator hjj
 * @date 2020-06-23
 * @class CesiumFun
 */
class CesiumFun {

    /**
     * @description 移除单个实体
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {string} layname 实体所在数据源名称
     * @param {string } id 实体id
     * @returns {boolean} 移除结果
     * @memberof CesiumFun
     */
    removeEntById(layname, id) {
        try {
            let tempds = this.getDSByName(layname);
            if (tempds === null) {
                return false;
            } else {
                let entitys = tempds.entities.values;
                for (let i of entitys) {
                    if (i.id === id) {
                        tempds.entities.remove(i);
                        return true;
                    }
                }
                return false;
            }
        } catch (e) {
            console.log(layname, "图层中删除", id, "对象失败！", e);
            return false;
        }
    }

    /**
     * @description 移除多个实体
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {string} layname 实体所在数据源名称
     * @param {Array.<string>} idArr 实体id数组
     * @returns {boolean} 移除结果
     * @memberof CesiumFun
     */
    removeEntByIds (layname, idArr) {
        try {
            let tempds = this.getDSByName(layname);
            if (tempds === null && idArr.length === 0) {
                return false;
            } else {
                let entitys = tempds.entities.values;
                for (let i = 0; i < entitys.length; i++) {
                    let pindex = idArr.includes(entitys[i].id);
                    if (pindex > -1) {
                        tempds.entities.remove(entitys[i]);
                        i--;
                        idArr.splice(pindex, 1);
                        if (idArr.length === 0) {
                            return true;
                        }
                    }
                }
                return false;
            }
        } catch (e) {
            console.log(layname, "图层中删除", idArr, "对象失败！", e);
            return false;
        }
    }

    /**
     * @description 获取符合特定属性值的实体
     * @author tpy
     * @annotator hjj
     * @date 2020-06-01
     * @param {String} layname 实体所在数据源名称
     * @param {String} propKey 属性名
     * @param {String} propValue 属性值
     * @returns {(Array.<Cesium.Entity> | null)} 满足要求的实体数组
     * @memberof CesiumFun
     */
    getEntityByProp (layname, propKey, propValue) {
        try {
            let tempds = this.getDSByName(layname);
            if (tempds === null) {
                return null;
            } else {
                let entitys = tempds.entities.values;
                let entityArr = [];
                //获取满足条件的实体
                for (let i of entitys) {
                    if (propKey === "id") {
                        if (i.id === propValue) {
                            entityArr.push(i);
                            return entityArr;
                        }
                    } else if (i.properties.getValue("")[propKey] === propValue) {
                        entityArr.push(i);
                    }
                }

                //返回结果
                if (entityArr.length) {
                    return entityArr;
                } else {
                    return null;
                }
            }
        } catch (e) {
            console.log(`${layname}图层中未找到${propKey}=${propValue}的实体对象`)
            return null;
        }
    }

    /**
     * @description 获取单个实体
     * @author tpy
     * @annotator hjj
     * @date 2020-06-01
     * @param {string} layname 实体所在数据源名称
     * @param {string} id 实体标识
     * @returns {(Cesium.Entity | null)} 实体
     * @memberof CesiumFun
     */
    getEntitybyID (layname, id) {
        let entityArr = this.getEntityByProp(layname, "id", id);
        if (entityArr && entityArr.length) {
            return entityArr[0];
        } else {
            return null;
        }
    }

    /**
     * @description 获取单个实体
     * @author tpy
     * @annotator hjj
     * @date 2020-06-01
     * @param {Array.<string>} laynames 数据源名称数组
     * @param {string} id 实体标识
     * @returns {(Cesium.Entity | null)} 实体
     * @memberof CesiumFun
     */
    getEntitybyIDs  (laynames, id) {
        try {
            for (let i of laynames) {
                let tempentiy = this.getEntitybyID(i, id);
                if (tempentiy !== null) {
                    return tempentiy;
                }
            }
        } catch (e) {
            console.log("图层中查找", id, "对象失败！", e);
        }
        return null;
    }

    /**
     * @description 查找数据源，若不存在则创建一个
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {string} layname 数据源名称
     * @returns {(Cesium.Datsource|null)} 数据源 
     * @memberof CesiumFun
     */
    dsgetbyname (layname) {
        try {
            let tempds = this.getDSByName(layname);
            if (tempds === null) {
                let tempds = new Cesium.CustomDataSource(layname);
                if(window.CesiumViewer && window.CesiumViewer.dataSources){
                    window.CesiumViewer.dataSources.add(tempds);
                }
                return tempds;
            } else {
                return tempds;
            }
        } catch (e) {
            console.log(layname, "图层创建失败！", e);
            return null;
        }
    }

    /**
     * @description 创建多个KML数据源
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {Array.<string>} laynameArr 数据源名称数组
     * @param {function} callback 回调函数
     * @returns {boolean} 创建结果
     * @memberof CesiumFun
     */
    kmldsCreate (laynameArr, callback)  {
        try {
            let viewer = window.CesiumViewer;
            for (let i = 0; i < laynameArr.length; i++) {
                let tempds = new Cesium.KmlDataSource({
                    camera: viewer.scene.camera,
                    canvas: viewer.scene.canvas
                });
                tempds._name = laynameArr[i];
                viewer.dataSources.add(tempds);
            }
            if (typeof (callback) == "function") {
                callback(null);
            }
            return true;
        } catch (e) {
            console.log("kml图层创建失败！", e);
            return false;
        }
    }

    /**
     * @description 判断数据源是否都存在
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {Array.<string>} laynameArr 数据源名称数组
     * @returns {boolean} 结果
     * @memberof CesiumFun
     */
    alldsExsit (laynameArr) {
        if (laynameArr && typeof (laynameArr) != "undefined") {
            for (let i = 0; i < laynameArr.length; i++) {
                let dsresult = this.getDSByName(laynameArr[i]);
                if (!dsresult) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    /**
     * @description 获取相机中心点坐标
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @returns {Object} 中心点坐标 {lon,lat,height}
     * @memberof CesiumFun
     */
    getCenterlnglat () {
        try {
            let center = window.CesiumViewer.camera.positionCartographic;
            return {
                lon: Cesium.Math.toDegrees(center.longitude),
                lat: Cesium.Math.toDegrees(center.latitude),
                height: center.height
            };
        } catch (e) {
            console.log("获取窗口中心坐标失败！", e);
            return { lon: 0, lat: 0, height: 0 };
        }

    }

    /**
     * @description 计算水质等级
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {number} gdhc 黑臭等级
     * @param {number} gddbs 地表水等级
     * @returns {number} 水质等级
     * @memberof CesiumFun
     */
    computeWQGrade (gdhc, gddbs) {
        return gdhc > 1 ? (6 + gdhc) : gddbs;
    }


    /**
     * @description 查找栅格影像图层
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {string} layname 图层名称
     * @returns {(Cesium.ImageryLayer | null)} 影像图层类
     * @memberof CesiumFun
     */
    getIMGByName (layname) {
        try {
            if(window.CesiumViewer && window.CesiumViewer.imageryLayers){
                let imageryLayers = window.CesiumViewer.imageryLayers;
                for (let i = 0; i < imageryLayers.length; i++) {
                    if (imageryLayers.get(i).name === layname) {
                        return imageryLayers.get(i);
                    }
                }
            }
        } catch (e) {
            console.log(layname, "图层(img)查找失败！", e);
        }
        return null;
    }

    /**
     * @description 查找栅格影像图层
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {string} urlstrr 影像服务地址
     * @returns {(Cesium.ImageryLayer | null)} 影像图层类
     * @memberof CesiumFun
     */
    getIMGByUrl (urlstrr) {
        try {
            let imageryLayers = window.CesiumViewer.imageryLayers;
            for (let i = 0; i < imageryLayers.length; i++) {
                if (imageryLayers.get(i).imageryProvider.url.indexOf(urlstrr) > -1) {
                    return imageryLayers.get(i);
                }
            }
        } catch (e) {
            console.log(urlstrr, "图层查找失败！", e);
        }
        return null;
    }

    /**
     * @description 查找s3m图层
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {string} layname 图层名称
     * @returns {(Cesium.S3MTilesLayer| null)} S3M(Spatial 3D Model)图层类
     * @memberof CesiumFun
     */
    getS3MByName (layname) {
        try {
            if(window.CesiumViewer && window.CesiumViewer.scene){
                let layeers = window.CesiumViewer.scene.layers._layers.values;
                for (let l = 0; l < layeers.length; l++) {
                    if (layeers[l].name === layname) {
                        return layeers[l];
                    }
                }
            }
        } catch (e) {
            console.log(layname, "图层(s3m)查找失败！", e);
        }
        return null;
    }

    /**
     * @description 查找Cesium.Datasource
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {string} layname 数据源名称
     * @returns {(Cesium.DataSource | null)} Cesium.Datasource
     * @memberof CesiumFun
     */
    getDSByName (layname) {
        try {
            if(window.CesiumViewer && window.CesiumViewer.dataSources){
                let dscollection = window.CesiumViewer.dataSources;
                for (let di = 0; di < dscollection.length; di++) {
                    if (dscollection.get(di).name === layname) {
                        return dscollection.get(di);
                    }
                }
            }
        } catch (e) {
            console.log(layname, "图层(ds)查找失败！", e);
        }
        return null;
    }

    /**
     * @description 移除数据源
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {string} layname 数据源名称
     * @memberof CesiumFun
     */
    removeDSByName(layname) {
        try {
            let tempds = this.getDSByName(layname);
            if (tempds !== null) {
                window.CesiumViewer.dataSources.remove(tempds);
            }
        } catch (e) {
            console.log(layname, "图层(ds)移除失败！", e);
        }
    }


    /**
     * @description 查找mvt矢量图层
     * @author hjj
     * @annotator hjj/dy
     * @date 2020-09-17
     * @param {string} layname 图层名称
     * @returns {(Cesium.VectorTilesLayer | null)} 矢量瓦片图层类
     * @memberof CesiumFun
     */
    getMVTByName(layname) {
        try {
            if(window.CesiumViewer && window.CesiumViewer.scene){
                let layers =  window.CesiumViewer.scene._vectorTileMaps._layers.values;
                for (let l = 0; l < layers.length; l++) {
                    if (layers[l].name === layname) {
                        return layers[l];
                    }
                }
            }
        } catch (e) {
            console.log(layname, "图层(mvt)查找失败！", e);
        }
        return null;
    }

    /**
     * @description 画布坐标转笛卡尔3坐标
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {Cesium.Cartesian2} position
     * @returns {(Cesium.Cartesian3 | null)}笛卡尔3坐标
     * @memberof CesiumFun
     */
    convertCanvasToCartesian3 (position) {
        try {
            let viewer = window.CesiumViewer
            var ray = viewer.camera.getPickRay(position);
            var cartesian = viewer.scene.globe.pick(ray, viewer.scene);
            return cartesian;
        } catch (e) {
            console.log("窗口坐标转笛卡尔坐标失败！", e);
            return null;
        }
    }

    /**
     * @description 面图层折点坐标转地理坐标
     * @author yjw
     * @annotator hjj
     * @date 2020-06-23
     * @param {Cesium.PolygonHierarchy} pHierarchy
     * @returns {Array} 转换结果
     * @memberof CesiumFun
     */
    convertHierCartesian3ToCarto(pHierarchy) {
        try {
            let dkcarts = pHierarchy.getValue("");
            let BoundCarts = dkcarts.positions;
            let BdLngLatArr = [];
            if (BoundCarts && BoundCarts.length > 0) {
                for (let di = 0; di < BoundCarts.length; di++) {
                    let lnglat = this.convertCartesian3ToCarto(BoundCarts[di]);
                    BdLngLatArr.push(lnglat);
                }
            }
            if (dkcarts.holes && dkcarts.holes.length > 0) {
                let holeLngLatArr = this.convertHierCartesian3ToCarto(dkcarts.holes);
                return [BdLngLatArr, holeLngLatArr];
            } else {
                return [BdLngLatArr];
            }
        } catch (e) {
            console.log("面图层折点转地理坐标出错：", e);
        }
        return undefined;
    }

    /**
     * @description 三维笛卡尔坐标转经纬度坐标
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {Cesium.Cartesian3} position 三维笛卡尔坐标
     * @returns {Object} 经纬度坐标 {lon,lat,height}
     * @memberof CesiumFun
     */
    convertCartesian3ToCarto (position) {
        try {
            let Cesium = window.Cesium;
            let cartographic = Cesium.Cartographic.fromCartesian(position);
            let longitudeString = Cesium.Math.toDegrees(cartographic.longitude);
            let latitudeString = Cesium.Math.toDegrees(cartographic.latitude);
            let heightString = cartographic.height;
            return { lon: longitudeString, lat: latitudeString, hei: heightString };
        } catch (e) {
            console.log("笛卡尔3坐标转经纬度失败！", e);
            return { lon: 0, lat: 0, hei: 0 };
        }
    }

    /**
     * @description 相机飞向指定的实体
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {string} layname 数据源名称
     * @param {string} id 实体id
     * @param {function} callback 回调函数
     * @memberof CesiumFun
     */
    flyToEntity (layname, id, callback) {
        if (layname == "RGCY" || layname == "GradeRGCY") {
            for (let i = 1; i < 10; i++) {
                let tds = this.getDSByName(layname + i);
                if (tds && tds.show) {
                    let target = this.getEntitybyID(layname + i, id);
                    if (target) {
                        window.CesiumViewer.flyTo(target, {
                            offset: {
                                heading: 0,
                                pitch: -1.7,
                                range: 4500
                            }
                        });
                        if (typeof (callback) == "function") {
                            let res = new Object();
                            res.id = target.id;
                            let points = this.convertCartesian3ToCarto(target.position.getValue(""));
                            res = { ...res, ...points };
                            callback(res);
                        }
                        break;
                    }
                    else {
                    }
                } else {
                }

            }
        } else {
            let stds = this.getDSByName(layname);
            if (stds && stds.show) {
                let target = this.getEntitybyID(layname, id);
                if (target) {
                    window.CesiumViewer.flyTo(target, {
                        offset: {
                            heading: 0,
                            pitch: -1.7,
                            range: 4500
                            // range: 70000
                        }
                    });
                    if (typeof (callback) == "function") {
                        let res = new Object();
                        res.id = target.id;
                        let points = this.convertCartesian3ToCarto(target.position.getValue(""));
                        res = { ...res, ...points };
                        callback(res);
                    }
                }
                else {
                    message.warning("未找到该对象，请确认图层已开启！");
                }
            } else {
                console.log("考勤定位", layname, stds);
                message.warning("对象所属图层关闭，无法定位！");
            }

        }
    }

    /**
     * @description 相机飞向指定的实体
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {Array.<string>} layArr 数据源名称数组
     * @param {string} id 实体id
     * @memberof CesiumFun
     */
    flyToEntityByDSArr(layArr, id) {
        let _this = this;
        if (layArr && layArr.length > 0) {
            for (let i = 0; i < layArr.length; i++) {
                // for(let i in layArr){
                let tds = _this.getDSByName(layArr[i].name);
                if (tds && tds.show) {
                    let target = _this.getEntitybyID(layArr[i].name, id);
                    if (target) {
                        window.CesiumViewer.flyTo(target, {
                            // window.CesiumViewer.zoomTo(target, {
                            offset: {
                                heading: 0,
                                pitch: -1.7,
                                range: 5000
                                // range: 70000
                            }
                        });
                        break;
                    }
                }
            }
        }
    }

    /**
     * @description 检查经纬度坐标合法性
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {number} lon
     * @param {number} lat
     * @returns {boolean} 检查结果
     * @memberof CesiumFun
     */
    checkLngLat (lon, lat) {
        let lonmark = false, latmark = false;
        if (typeof (lon) !== "undefined" && lon > -180 && lon < 180) {
            lonmark = true;
        }
        if (typeof (lat) !== "undefined" && lat > -90 && lat < 90) {
            latmark = true;
        }
        return lonmark && latmark;
    }

    /**
     * @description 比较两个点坐标是否一致
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {Object} pointF {x,y,z} 第一个坐标点
     * @param {Object} pointS {x,y,z} 第二个坐标点
     * @returns {boolean} 比较结果
     * @memberof CesiumFun
     */
    comparePointsXYZ(pointF, pointS) {
        try {
            if (pointF.x && pointS.x && pointF.y && pointS.y && pointF.z && pointS.z) {
                let lngF = pointF.x.toFixed(6);
                let lngS = pointS.x.toFixed(6);
                let latF = pointF.y.toFixed(6);
                let latS = pointS.y.toFixed(6);
                let heiF = pointF.z.toFixed(6);
                let heiS = pointS.z.toFixed(6);
                if (lngF === lngS && latF === latS && heiF === heiS) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } catch (e) {
            console.log("坐标比较失败！", e);
            return false;
        }
    }

    /**
     * @description 比较两个点坐标是否一致
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {Object} pointF {lon,lat,hei} 第一个坐标点
     * @param {Object} pointS {lon,lat,hei}  第二个坐标点
     * @param {boolean} zmark 是否比较Z分量 
     * @returns {boolean} 比较结果
     * @memberof CesiumFun
     */
    comparePointsLonLat(pointF, pointS, zmark) {
        try {
            let baseexist = pointF.lon && pointS.lon && pointF.lat && pointS.lat;
            if (zmark) {
                baseexist = baseexist && pointF.hei && pointS.hei;
            }
            if (baseexist) {
                let lngF = pointF.lon.toFixed(6);
                let lngS = pointS.lon.toFixed(6);
                let latF = pointF.lat.toFixed(6);
                let latS = pointS.lat.toFixed(6);
                let basemark = lngF === lngS && latF === latS;
                if (zmark) {
                    let heiF = pointF.hei.toFixed(6);
                    let heiS = pointS.hei.toFixed(6);
                    basemark = basemark && heiF === heiS;
                }
                if (basemark) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } catch (e) {
            console.log("坐标比较失败！", e);
            return false;
        }
    }

    /**
     * @description 比较两个点坐标是否一致
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {Array.<number>} pointF [x,y] 第一个坐标点
     * @param {Array.<number>} pointS [x,y] 第二个坐标点
     * @returns {boolean} 比较结果
     * @memberof CesiumFun
     */
    comparePointsArray(pointF, pointS) {
        try {
            if (pointF[0] && pointS[0] && pointF[1] && pointS[1]) {
                let lngF = pointF[0].toFixed(6);
                let lngS = pointS[0].toFixed(6);
                let latF = pointF[1].toFixed(6);
                let latS = pointS[1].toFixed(6);
                if (lngF === lngS && latF === latS) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }

        } catch (e) {
            console.log("坐标点比较失败！", e);
            return false;
        }
    }

    /**
     * @description 复制实体
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {Cesium.Entity} entity 被复制的实体
     * @param {string} idstr 实体id
     * @returns {Cesium.Entity} 结果
     * @memberof CesiumFun
     */
    copyEntity(entity, idstr) {
        try {
            let newentity = new window.Cesium.Entity({ id: idstr });
            for (let i of keystr) {
                newentity[i] = entity[i];
            }
            return newentity;
        } catch (e) {
            console.log("实体复制出错:", e);
        }
        return null;
    }

    /**
     * @description 坐标对象(经纬度)转数组
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {Object} lnglat {lon,lat}
     * @returns {Array.<number>} 结果数组 [x,y]
     * @memberof CesiumFun
     */
    convertLngLatToArr (lnglat) {
        try {
            if (lnglat) {
                return [lnglat.lon, lnglat.lat]
            }
        } catch (e) {
            console.log("坐标转数组出错:", e);
        }
    }

    /**
     * @description 十进制转十六进制
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {string} str 待转换的十进制文本
     * @returns {string} 转换后的十六进制文本
     * @memberof CesiumFun
     */
    convertDecimalToHexadecimal (str) {
        var colorStr = parseInt(str, 10).toString(16);

        if (colorStr.length === 1) {
            colorStr = '0' + colorStr;
        }

        return colorStr;
    }

    /**
     * @description 颜色转换，rgba转16进制
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {sting} colorStr RGBA
     * @returns {Object} {color,alpha} 转换结果
     * @memberof CesiumFun
     */
    convertRGBAToHexadecimal(colorStr) {
        let color = colorStr;
        let alpha = 1;

        if (/^rgb\(\d+,\d+,\d+\)$/i.test(colorStr)) {
            let execs = /^rgb\((\d+),(\d+),(\d+)\)$/i.exec(colorStr);

            color = '#' + this.convertDecimalToHexadecimal(execs[1]) + this.convertDecimalToHexadecimal(execs[2]) + this.convertDecimalToHexadecimal(execs[3]);
        } else if (/^rgba\(\d+,\d+,\d+,\d+(\.\d*)?\)$/i.test(colorStr)) {
            let execs = /^rgba\((\d+),(\d+),(\d+),(\d+(\.\d*)?)\)$/i.exec(colorStr);

            color = '#' + this.convertDecimalToHexadecimal(execs[1]) + this.convertDecimalToHexadecimal(execs[2]) + this.convertDecimalToHexadecimal(execs[3]);
            alpha = parseFloat(execs[4]);
        } else if (/^#/.test(colorStr)) {
            if (colorStr.length > 7) {
                let alphaStr = colorStr.substr(7, 2).toLowerCase();
                let arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];

                color = colorStr.substr(0, 7);
                if (alphaStr.length === 1) {
                    alpha = arr.indexOf(alphaStr[0]) / 255;
                } else {
                    alpha = (16 * arr.indexOf(alphaStr[0]) + arr.indexOf(alphaStr[1])) / 255;
                }
            }
        }

        return { color, alpha };
    }

    /**
     * @description 获取面数据源
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {Array.<string>} LayArr 数据源名称数组
     * @returns {Array.<Cesium.DataSource>} 数据源数组
     * @memberof CesiumFun
     */
    getPolyLayer (LayArr) {
        return this._geoLayerArr(LayArr, "polygon");
    }

    /**
     * @description 获取线数据源
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {Array.<string>} LayArr 数据源名称数组
     * @returns {Array.<Cesium.DataSource>} 数据源数组
     * @memberof CesiumFun
     */
    getLineLayer (LayArr) {
        return this._geoLayerArr(LayArr, "polyline");
    }

    /**
     * @description 获取数据源数组
     * @author tpy
     * @annotator hjj
     * @date 2020-06-23
     * @param {Array.<string>} LayArr 数据源名称数组
     * @param {string} geotype 几何类型
     * @returns {Array.<Cesium.DataSource>} 数据源数组
     * @memberof CesiumFun
     * @private
     */
    _geoLayerArr(LayArr, geotype) {
        try {
            let resultArr = [];
            let pCesiumFun = new CesiumFun();
            if (LayArr && LayArr.length > 0) {
                for (let i = 0; i < LayArr.length; i++) {
                    try {
                        let item = LayArr[i];
                        let itemlay = pCesiumFun.getDSByName(item.name);
                        if (itemlay != null) {
                            let entitys = itemlay.entities.values;
                            for (let j = 0; j < entitys.length; j++) {
                                try {
                                    let itementity = entitys[j];
                                    if (itementity[geotype]) {
                                        resultArr.push(item);
                                        break;
                                    }
                                } catch (e) {
                                    console.log(item.name, "数据集解析出错:", e);
                                }
                            }
                        }
                    } catch (e) {
                        console.log("图层遍历出错:", e);
                    }
                }
            }
            return resultArr;
        } catch (e) {
            console.log("面图层提取出错:", e);
        }
    }
}
export { CesiumFun }